<?php
namespace Mob \ Model;

use Think \ Model;
use Think \ Hook;
/**请求模型
 * Class InfoModel
 */

require_once ('./Application/Mob/Common/function.php');

class SignModel extends Model {

   protected $tableName = 'signrecord';


   public function creatorRecord($signUid,$signOpenId,$latitude,$longitude,$studentId,$schooId,$signStatus,$destLongitude,$destLatitude,$signDistance=0)
   {
   	$data['serialno']=getSerialno(24);
   	$data['signUid']=$signUid;
   	$data['signOpenId']=$signOpenId;
   	$data['latitude']=$latitude;
   	$data['longitude']=$longitude;
   	$data['studentId']=$studentId;
   	$data['schooId']=$schooId;
   	$data['signStatus']=$signStatus;
   	$data['signDistance']=$signDistance;
   	$data['destLongitude']=$destLongitude;
   	$data['destLatitude']=$destLatitude;
   	$data['signTime']= time();
   	if($this->add($data))
   	{
   	return 	$data;

   	}

   }
   public function is_existSign($signUid)
   {
   $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
   $where = array('signTime'=>array('gt',$beginToday),'signUid'=>$signUid,'signStatus'=>1,);
   $count = $this->where($where)->count();
   if($count>0)
   {
   return true;
   }else
   {
   return false;
   }
   }
   public function get_historySign($signUid)
   {
   	$where = array('signUid'=>$signUid,'signStatus'=>1);
   	$res = $this->where($where)->field('signTime,studentId,signUid,latitude,longitude')->order('signTime desc')->select();
   	$count =1;
   	foreach($res as  &$v)
   	{
    $v['sortId']=$count;
    $count++;

   	}
   	return $res;

   }
   public function get_IntradaySign($signUid)
   {
  $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
  $where = array('signUid'=>$signUid,'signStatus'=>1,'signTime'=>array('gt',$beginToday));
  return $this->where($where)->field('signTime,signUid,latitude,longitude,studentId')->find();

   }

 public function rad($d)
  {
	return $d * 3.1415926535898 / 180.0;
  }
public function GetDistance($lat1, $lng1, $lat2, $lng2)
{
	$EARTH_RADIUS = 6378.137;
	$radLat1 = $this->rad($lat1);
	//echo $radLat1;
	$radLat2 = $this->rad($lat2);
	$a = $radLat1 - $radLat2;
	$b = $this->rad($lng1) - $this->rad($lng2);
	$s = 2 * asin(sqrt(pow(sin($a/2),2) +
	cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)));
	$s = $s *$EARTH_RADIUS;
	$s = round($s * 10000) / 10000;
	return $s*1000;
}
public function verifyDistance($lat1, $lng1, $lat2, $lng2,$distance=50)
{
	$aDistance =$this->GetDistance($lat1, $lng1, $lat2, $lng2);
	if($aDistance<$distance)
	{
	return true;
	}else
	{
	return false;
	}




}
   public function get_LastSignRecord($uid,$selectDay='')
   {
      $sing = new \ Think \ Model();
      if(empty($selectDay))
      {
     $selectDay = mktime(0,0,0,date('m'),date('d'),date('Y'));
     $endDay= mktime(0,0,0,date('m'),date('d')+1,date('Y'));

      }else
      {


       $endDay=strtotime($selectDay)+86400;
       $selectDay=strtotime($selectDay);

      }


    $res=  $sing->query("select signTime,FROM_UNIXTIME(signTime,'%Y-%m-%d') as signdate,signUid,signStatus,studentId,latitude,longitude from __PREFIX__signrecord where serialno = (select max(serialno) from  __PREFIX__signrecord s where s.signTime >= $selectDay and s.signTime < $endDay and s.signUid =$uid  limit 1 ) limit 1 ;")[0];
    if(empty($res))
    {
    $res = array('signStatus'=>0,'signdate'=>date('Y-m-d',$selectDay));
    }
    return $res ;


   }

   public function  get_ClassSignDetails($classId)
   {
   	$class = D('Student')->queryClassPersonnel($classId,10183,1);



   	foreach($class as &$v)
   	{
   	$res =$this->get_LastSignRecord($v['Uid']);
   	if(empty($res))
   	{
   	$v['signStatus']=0;
   	}else
   	{
   	$v['signStatus']=$res['signStatus'];
   	}

   	$v['signTime']=$res['signTime'];

   	}
    unset($v);

   return $class;

   }
   public function qeuryClassSignStatus($classId,$schoolId='10183')
   {

   $class = D('Student')->queryClassPersonnel($classId,10183,1);


   $signSuccess=0;  //签到成功数
   $signFailure = 0; //签到失败数
   $nosign=0;       //没有签到数
   foreach($class as $v)
   {
   $sing = $this->get_LastSignRecord($v['Uid']);

   if(empty($sing))
   {
   	$nosign++;
   }
   if($sing['signStatus']==1)
   {
   	 $signSuccess++;
   }elseif($sing['signStatus']==2)
   {
   	$signFailure++;
   }

   }

   $status['signSuccess']=$signSuccess;
   $status['signFailure']=$signFailure;
   $status['nosign']=$nosign;
   return $status;

   }

  public function get_timelist($startDay='',$engDay='',$isWeekend=false)
  {
    $array = array();  //定义数组
  	if(empty($startDay))  //判断开始时间是否定义
  	{
     $startDay=  date('Y-m-d',strtotime('-90 day'));  //如果没有定义，则默认为提前90天
  	}
  	if(empty($engDay))
  	{
    $engDay=  date('Y-m-d');
  	}

    $begin = strtotime($startDay);
    $end = strtotime($engDay);
   for($i=$begin; $i<=$end;$i+=(24*3600))
    {
     if($isWeekend==false)
     {
      if(date('w',$i)!=6&&date('w',$i)!=0)
      {
        array_push($array,date("Y-m-d",$i));

      }
     }else
     {
      array_push($array,date("Y-m-d",$i));
     }
    }

    return $array;

  }

  public function get_personalSign1($uid,$day=30,$isWeekend=true)
  {

  $day = $this->get_SignTime($day);  //取默认90天的考勤日期;
$startDay =$day['time']['startDay']; //取统计的开始时间
$endDay=$day['time']['endDay'];   //取统计的结束时间
$signDay = $day['Day'];
$record = array();///初始化签到记录
$signSuccess=0;  //签到成功数
$signFailure = 0; //签到失败数
$nosign=0;       //没有签到数
$leave = 0;      //请假天数
 //$signRecord = $this->query("select FROM_UNIXTIME(signTime,'%Y-%m-%d') as signdate,signUid,max(signTime) as lastTime ,signStatus  from ocenter_signrecord  where signTime >= $startDay and signTime < $endDay and signUid =$uid
//group by FROM_UNIXTIME (signTime,'%Y-%m-%d')");
$signRecord = $this->query("select FROM_UNIXTIME(f.signTime,'%Y-%m-%d') as signdate,s.signUid,s.signStatus from   ocenter_signrecord s , (select FROM_UNIXTIME(signTime,'%Y-%m-%d') as signdate,signUid,max(signTime) as signTime
  from ocenter_signrecord  where signTime >= $startDay and signTime < $endDay and signUid =$uid group by FROM_UNIXTIME (signTime,'%Y-%m-%d')) f where s.signTime = f.signTime and s.signUid = f.signUid");


sort($signDay); //把时间重新排下序

foreach($signDay as $day)  //遍历所有需要签到的日期
{
$record[date('Y-m-d',$day)]=null;  //先初始化当天数据
foreach($signRecord as $sign)  //遍历所有已经签到的日期
{
 if(date('Y-m-d',$day)==$sign['signdate'])  //判断当天日期是否有签到记录
 {
 if($sign['signStatus']==1) //如果签到是否为成功
 {
 $signSuccess++;    //成功数加1
 }elseif($sign['signStatus']==2)  //如果签到结果为失败
 {
 $signFailure++;    //失败数加1
 }
 $record[date('Y-m-d',$day)] = array('signStatus'=>$sign['signStatus'],'signdate'=>date('Y-m-d',$day));

 }

}

if($record[date('Y-m-d',$day)]==null)  //判断当天签到结果是否为空
{
$record[date('Y-m-d',$day)] = array('signStatus'=>0,'signdate'=>date('Y-m-d',$day));
$nosign++;  //未签到数加1
}

}
  return array('Record'=>$record,'nosign'=>$nosign,'signSuccess'=>$signSuccess,'signFailure'=>$signFailure,'leave'=>$leave);
}
    public function get_personalSign($uid,$day='',$isWeekend=false)
  {

 $timelist = $this->get_timelist($day,null,$isWeekend);
  $signRecord = array();
  $singResult = array();
  // $startDay = $timelist[0];
  // $endDay = $timelist[count($timelist)-1];
//  $startDay=strtotime($day);
  $startDay = empty($day)?strtotime(date('Y-m-d'))-86400*90:strtotime($day);
  $endDay=strtotime(date('Y-m-d'))+86400;
   $signSuccess=0;  //签到成功数
   $signFailure = 0; //签到失败数
   $nosign=0;       //没有签到数
   $leave = 0;      //请假天数
   $signRecord = $this->query("select FROM_UNIXTIME(signTime,'%Y-%m-%d') as signdate,signUid,max(signTime) as lastTime ,signStatus  from ocenter_signrecord  where signTime >= $startDay and signTime < $endDay and signUid = $uid
   group by FROM_UNIXTIME (signTime,'%Y-%m-%d')");

  $leaveRecord = D('Leave')->personLeaveRecordByDate($uid);


//  return  $signRecord;
 foreach($timelist as $t=>$key)
 {

  foreach($signRecord as $v)
  {
  if($key==$v['signdate'])
  {
  $singResult[$key]=$v;
    if($v['signStatus']==1)
    {
    $signSuccess++;
    }elseif($v['signStatus']==2)
    {
    $signFailure++;
    }

  }
  break;
  }


  if(empty($singResult[$key]['signStatus']))
  {

   if(empty($leaveRecord))
   {
    $singResult[$key]=array('signStatus'=>0,'signdate'=>$key);
  $nosign++;
   }else
   {

   foreach($leaveRecord as $l)
  {

  if($l['date']==$key&&$l['approvalFlg']==1)
  {

   $singResult[$key]=array('signStatus'=>4,'signdate'=>$key);

  $leave++;
  }else
  {
  if($singResult[$key]==null)
  {
  $singResult[$key]=array('signStatus'=>0,'signdate'=>$key);
  $nosign++;

        }
       }
      }
     }
    }
   }

  return array('Record'=>$singResult,'nosign'=>$nosign,'signSuccess'=>$signSuccess,'signFailure'=>$signFailure,'leave'=>$leave);
  }


   /**
	 * get_ContinuousNotSignTop  取连续未签到次数排行
	 * @return bool
	 * @author:wanghongyan
	 */

  public function get_ContinuousNotSignTop($teacherId,$schooId='10183',$start,$end)
  {

  $teacher = D('Teacher');   //实例化teacher 导员类
  $student = $teacher->get_ClassGroupUid($teacherId,$schooId);  //取导员涉及到的学生信息


  $start= empty($start)?mktime(0,0,0,date('m'),date('d')-90,date('Y')):strtotime($start);  //转换开始时间为时间戳类型
   $end= empty($end)?mktime(0,0,0,date('m'),date('d')+1,date('Y')):strtotime($end);          //转换结束时间为时间戳类型
  $endTime = $end-86400;
 //  $end= empty($end)?mktime(0,0,0,date('m'),date('d'),date('Y')):strtotime($end);
  $signRecord = array();

   $sign = new \ Think \ Model();
   $lastSignRecord = $sign->query("select s.Uid,s.name,o.orgaId,o.organame,o.teacherId,max(d.signTime) as signTime,FROM_UNIXTIME(max(d.signTime),'%Y-%m-%d') as signdate from ocenter_student s,ocenter_orga o,ocenter_signrecord d where s.ClassId = o.orgaId and o.orgaType =3 and teacherId = $teacherId
   and s.Uid = d.signUid and o.schooId = d.schooId and o.schooId =$schooId and o.teacherId = $teacherId and d.signTime >= $start and d.signTime < $end group by s.Uid");

   foreach($student as $s)  //遍历所有学生
   {
   $signRecord[$s['Uid']] = null;   //设置各学生初始值
   $notSignDay=null;   //设置没有签到日期为空
    $notSignDay = array();
    foreach($lastSignRecord as $l) //遍历所有学生的最后签到记录
    {
       $notsignCount=0;

      if($s['Uid']==$l['Uid'])   //判断当前学生与最后签到人相符
      {
      $lastSignDay = strtotime($l['signdate']); //取学生最后签到日期的时间戳

      if($lastSignDay==$endTime)   //判断一下最后的签到时间是不是签到的截止日期
      {
      $notSignDay=null;

      }else
      {
      $startDay=$lastSignDay+86400; //计算时间从最后签到日期后的第一天开始算
       for($i=$startDay;$i<$end;$i+=(24*3600))  //开始循环最后一次签到时间加一天
      {
       if($this->is_SignDay($i))
       {
       array_push($notSignDay,date('Y-m-d',$i));
       $notsignCount++;
       }
      }
      }
        $signRecord[$s['Uid']]= array('signUid'=>$s['Uid'],'notSignDaySum'=>$notsignCount,'notSingDay'=>$notSignDay,'classId'=>$s['orgaId'],'name'=>$s['name'],'studentId'=>$s['studentId']);
        break;

      }

    }
   if($signRecord[$s['Uid']] == null) //判断一下当前是否为
   {
   	 $startDay=$start; //计算时间从最后签到日期后的第一天开始算
       for($i=$startDay;$i<$end;$i+=(24*3600))  //开始循环最后一次签到时间加一天
      {
       if($this->is_SignDay($i))
       {
       array_push($notSignDay,date('Y-m-d',$i));

       $notsignCount++;
       }

      }

     $signRecord[$s['Uid']]= array('signUid'=>$s['Uid'],'notSignDaySum'=>$notsignCount,'notSingDay'=>$notSignDay,'classId'=>$s['orgaId'],'name'=>$s['name'],'studentId'=>$s['studentId']);
     }
   }

    $signRecord = $this->multi_array_sort($signRecord,'notSignDaySum');  //按照未连续签到时间倒排序
    $signRecord = $this->multi_array_top($signRecord,'notSignDaySum',3);
    foreach($signRecord as &$v)
    {
    $v['OrgaInfo']= D('Orga')->get_OrgaFullInfo($v['classId']);

    }
    unset($v);

    return $signRecord;


  }
    public function get_NotSignTopFate($teacherId,$schooId='10183',$start,$end)
    {
     $teacher = D('Teacher');   //实例化teacher 导员类
     $student = $teacher->get_ClassGroupUid($teacherId,$schooId);  //取导员涉及到的学生信息

  $start= empty($start)?mktime(0,0,0,date('m'),date('d')-90,date('Y')):strtotime($start);  //转换开始时间为时间戳类型
   $end= empty($end)?mktime(0,0,0,date('m'),date('d')+1,date('Y')):strtotime($end);          //转换结束时间为时间戳类型
    $signRecord= array();

   $startDay = date('Y-m-d',$start);
    foreach($student as $v)  //遍历所有学生
    {


    $res =$this->get_personalSign($v['Uid'],$startDay);
     $signRecord[$v['Uid']]=array('Uid'=>$v['Uid'],'studentId'=>$v['studentId'],'name'=>$v['name'],'classId'=>$v['orgaId'],'signSuccess'=>$res['signSuccess'],'signFailure'=>$res['signFailure'],'nosign'=>$res['nosign']);

    }
    unset($v);
   $signRecord = $this->multi_array_sort($signRecord,'nosign');
   $signRecord = $this->multi_array_top($signRecord,'nosign',3);
   foreach($signRecord as &$v)
   {
   $v['OrgaInfo']= D('Orga')->get_OrgaFullInfo($v['classId']);

   }
   return $signRecord;

  }

    /**
	 * is_SignDay  判断日期是否需要签到
	 * @return bool
	 * @author:wanghongyan
	 */

  public function is_SignDay($day,$isWeekend=false)
  {
  	if($isWeekend)
  	{
  	return true;
  	}else
  	{

  	if(date('w',$day)==5&&date('w',$day)==6)
  	{
  	return false;
  	}
  	else
  	{
  	return true;
  	}

  	}

  }
      /**
	 * multi_array_sort  数组排序
	 * @return bool
	 * @author:wanghongyan
	 */



public function multi_array_sort($multi_array,$sort_key,$sort=SORT_DESC){
if(is_array($multi_array)){
foreach ($multi_array as $row_array){
if(is_array($row_array)){
$key_array[] = $row_array[$sort_key];
}else{
return false;
}
}
}else{
return false;
}
array_multisort($key_array,$sort,$multi_array);
return $multi_array;
}

public function multi_array_top($array,$value,$minNum)
{
 $arr = array();

 foreach($array as $v)
 {
  if($v[$value]>$minNum)
  {

  array_push($arr,$v);

  }

 }
  return $arr;
}

public function is_vacation($schooId,$day='')
{
 $day=empty($day)?mktime(0,0,0,date('m'),date('d')-90,date('Y')):strtotime($day);
  $where = array('schooId'=>$schooId,'status'=>1,'startDay'=>array('ELT',$day),'endDay'=>array('GT',$day));
  $vacaction = M('vacation');
 return  $vacaction->where($where)->find();


}

public function get_BeforeDate($day=3,$beginDay='',$isWeekend=false)
{

 $endDay = empty($beginDay)?mktime(0,0,0,date('m'),date('d'),date('Y')):strtotime($beginDay);  //取结束时间，如果没有的话，默认是当前时间

  if($isWeekend)  //如果周末也需要签到的话，
  {
  $startDay = $endDay-(3*24*3600);//默认开始时间
  }else
  {
   $temp = $endDay;
   $count=0;
   while($count<$day)
 {
 if(date('w',$temp)!=5&&date('w',$temp)!=6)//判断前一天是不是周末
 {
// print_r('local:'.date('Y-m-d',$temp));
$count++;
 }
$startDay = $temp;
$temp-=(86400);

 }
  }
 return $day= array('startDay'=>$startDay,'endDay'=>$endDay);

}

  public function get_ClassContinuousNotSignTop($classId,$schooId='10183',$Day=3,$start='',$end='')
  {
  $classStudent = D('Student')->queryClassPersonnel($classId,$schooId,1); //取班组所有学生
  $SignRecord= array();
  $sign = new \ Think \ Model();
   $start= empty($start)?mktime(0,0,0,date('m'),date('d')-30,date('Y')):strtotime($start);  //转换开始时间为时间戳类型
   $end= empty($end)?mktime(0,0,0,date('m'),date('d')+1,date('Y')):strtotime($end);          //转换结束时间为时间戳类型
  $lastSignRecord = $sign->query(" select s.Uid,s.studentId,s.ClassId,s.name,max(d.signTime) from   ocenter_student s,ocenter_signrecord d where d.signUid = s.Uid  and s.ClassId = $classId and s.verificFlag =1 and s.schooId = $schooId  and d.schooId = s.schooId
 and d.signTime >= $start and d.signTime < $end  group by s.Uid,s.studentId,s.ClassId,s.name");  //取到最后登录的日期


  }

 public function is_SignTime($schooId,$collegeId)
{
$signParam = D('SignParam')->get_param($schooId,$collegeId);
 $time = date('His',time());  //获取当前时间
 $beginSingTime = str_replace(':',null,$signParam['signStartTime']) ;  //允许签到开始时间
 $endSingTime =  str_replace(':',null,$signParam['signEndTime']) ;  //允许签到开始时间
 $isWeekend=$signParam['isWeekend'];
 if(!$isWeekend)   //判断周末是否需要签到
 {
  if(date('w',$day)==5||date('w',$day)==6)//判断前一天是不是周末
  {
  return false;

  }

 }
 if($time>=$beginSingTime&&$time<=$endSingTime)
 {
 return true;
 }
}

public function get_SignTime($day=3,$beginDay='',$isWeekend=false)
{
 $signDay = array();  //定义具体要签到的日期数组
 $endDay = empty($beginDay)?mktime(0,0,0,date('m'),date('d'),date('Y')):strtotime($beginDay);  //取结束时间，如果没有的话，默认是当前时间
  if($isWeekend)  //如果周末也需要签到的话，
  {
  $startDay = $endDay-(3*24*3600);//默认开始时间
  for($i=$startDay;$i<=$endDay;$i+=(24*3600))
  {
  array_push($signDay,$i);
  }
  }else
  {
   $temp = $endDay;
   $count=0;
   while($count<$day)
 {
 if(date('w',$temp)!=5&&date('w',$temp)!=6)//判断前一天是不是周末
 {
// print_r('local:'.date('Y-m-d',$temp));
$count++;
 array_push($signDay,$temp);
 }
$startDay = $temp;
$temp-=(86400);
 }
 rsort($signDay);  //时间重新排序
  }
return  array('time'=>array('startDay'=>$startDay,'endDay'=>$endDay+86399),'Day'=>$signDay); //结束时间为当天的23:59:59秒。
}

/// 班组近期签到统计
public function get_classRecentSignStatus($classId,$schooId='10183',$day=3)
{

$studentSignRecord = array(); //初始化学生签到记录
$SignDay = $this->get_SignTime($day)['Day'];   ///取近期需要签到的日期
$signClass = D('Student')->queryClassPersonnel($classId,$schooId,1); //取班组正常状态学生
$day=array();
foreach($signClass as $v)   //遍历学生班组数组
{
$daySign=array();
foreach($SignDay as $s=>$key)  //遍历每天需要签到的
{
$res = $this->get_DateSignStatus($v['studentId'],$key); //取当日签到结果
$res =empty($res)?2:1; //判断签到结果状态
array_push($daySign,array('date'=>$key,'status'=>$res,'day'=>date('j',$key))); //插到数据里
/*
print_r("res:".$res);
print_r("<br>");
print_r(M()->getLastSql());
print_r("<br>");
*/

}

$studentSignRecord[$v['studentId']]=array('studentId'=>$v['studentId'],'name'=>$v['name'],'uid'=>$v['Uid'],'signRecord'=>$daySign);  //初始化学生信息


}
unset($v);//释放变量
$day = array();
foreach($SignDay as $s)
{
array_push($day,date('j',$s));
}

return array('StudentSign'=>$studentSignRecord,'signDay'=>$day);

}
public function get_ClassSignStatus($classId,$schooId='10183')
{
 $sign = new \ Think \ Model();
 $end=strtotime(date('Y-m-d'));
 $start=$end-86400;
$res =  $sign->query("select t.Uid,t.verificFlag,t.ClassId,t.name,t.studentId,ifnull(f.signStatus,0) as signStatus,f.signTime from  ocenter_student t left join(select
d.serialno,d.signTime,d.signUid,d.signStatus,d.studentId from ocenter_signrecord  d,(select max(signTime) as signTime,signUid from
ocenter_signrecord where signTime >= $start and signTime < $end group by signUid) s where  d.signTime = s.signTime and d.signUid =
s.signUid ) f on t.studentId = f.studentId  and t.verificFlag = 1 and t.Uid = f.signUid where t.ClassId = $classId and schooId = $schooId");
$totalNum = 0;   //班级学生数
$signSucceedNum=0;  //签到成功数
$signFailureNum=0;  //签到失败数
$notSignNum=0;     //未签到数
$leaveNum=0;


foreach($res as $v)
{
if($v['signStatus']==0)
{
$notSignNum++; //未签到次数加1
}elseif($v['signStatus']==1)
{
$signSucceedNum++;  //签到成功次数加1
}elseif($v['signStatus']==2)
{
$signFailureNum++; //签证失败次数加1
}

$totalNum++; //人数加1
}
return array('totalNum'=>$totalNum,'signSucceedNum'=>$signSucceedNum,'signFailureNum'=>$signFailureNum,'notSignNum'=>$notSignNum,'leaveNum'=>$leaveNum);



}

public function get_DateSignStatus($studentId,$day)
{
 $end =	$day+86399;
 $sign = new \ Think \ Model();
 return $sign->query("SELECT signTime,signUid,longitude,latitude,studentId FROM ocenter_signrecord WHERE signTime >= $day and signTime  < $end AND studentId = $studentId AND signStatus = 1 LIMIT 1")[0];

}

public function get_SignSituation($schooId='10183',$day=null)
{
 $sign = new \ Think \ Model();
 $startTime = empty($day)?strtotime(date('Y-m-d')):strtotime($day);
 $endTime = $startTime+86400;
 return $sign->query("select count(*) as signNum,IFNULL(sum(if(signStatus=1,1,0)),0) as signSucceedNum,IFNULL(sum(if(signStatus=2,1,0)),0) as signFailureNum,count(distinct(signUid)) SignPeopleNum,FORMAT(IFNULL(IFNULL(sum(if(signStatus=1,1,0)),0)/count(distinct(signUid)),0)*100,2) as successRate from ocenter_signrecord where signTime >= $startTime and signTime < $endTime and schooId = $schooId limit 1")[0];
}
public function get_allowSignTime($schooId,$collegeId)
{
$signParam = D('SignParam')->get_param($schooId,$collegeId);
 $time = date('His',time());  //获取当前时间
 $beginSingTime = str_replace(':',null,$signParam['signStartTime']) ;  //允许签到开始时间
 $endSingTime =  str_replace(':',null,$signParam['signEndTime']) ;  //允许签到开始时间
 return array('beginSingTime'=>$beginSingTime,'endSingTime'=>$endSingTime);


}












}